import { createStore } from "vuex";
import createPersistedState from "vuex-persistedstate";

export default createStore({
  state: {
    isSignIn: false, // 登录接口 token返回成功设置为true
    loadingShow: false, // 请求遮罩
    configureInfo: {}, // 公司配置
    changePeopleList: [], //预订页 选中出行人
    publicAndPrivateFlag: "0", // 因公因私
    allChangeTripPeopleList: {}, // 预订页 所有房间选中的出行人
    userInfo: {}, // 个人信息
    searchParam: {}, // 用车搜索的参数进行保存  已保证返回搜索页进行数据的回填
    carInfo: {}, // 保存选中的车辆详细信息
    top_active: 2 // 用车订单 我的订单 全部订单
  },
  mutations: {
    TOGGLE_LOADING(state, data) {
      state.loadingShow = data;
    },
    SET_USER_INFO(state, data) {
      state.userInfo = Object.assign(state.userInfo, data);
    },
    SET_CONFIGURE_INFO(state, data) {
      state.configureInfo = Object.assign(state.configureInfo, data);
    },
    IS_SIGNIN(state, data) {
      state.isSignIn = data;
    },
    SET_CHANGE_PEOPLE_LIST(state, data) {
      state.changePeopleList = data;
    },
    SET_PUBLIC_ADN_PRIVATE_FLAG(state, data) {
      state.publicAndPrivateFlag = data;
    },
    SET_ALL_CHANGE_TRIP_PEOPLE_LIST(state, data) {
      state.allChangeTripPeopleList = data;
    },
    SET_SEARCH_PARAM(state, data) {
      state.searchParam = data;
    },
    SET_CAR_INFO(state, data) {
      state.carInfo = data;
    },
    SET_TOP_ACTIVE(state, data) {
      state.top_active = data;
    }
  },
  actions: {},
  modules: {},
  plugins: [
    createPersistedState({
      key: "mobile-cost-vuex",
      storage: window.sessionStorage,
      reducer(val) {
        return {
          userInfo: val.userInfo,
          configureInfo: val.configureInfo
        };
      }
    })
  ]
});
